package io.kiki.sba.registry.server.clientInterface.store;

import io.kiki.sba.registry.common.model.store.BaseInfo;
import lombok.Getter;

import java.util.Objects;

public class DataPos {
    @Getter
    private final String registerId;
    @Getter
    private final String dataInfoId;
    private int hash;

    public DataPos(String dataInfoId, String registerId) {
        this.dataInfoId = dataInfoId;
        this.registerId = registerId;
    }

    public static DataPos of(BaseInfo baseInfo) {
        return new DataPos(baseInfo.getDataInfoId(), baseInfo.getRegisterId());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        DataPos dataPos = (DataPos) o;
        return Objects.equals(registerId, dataPos.registerId) && Objects.equals(dataInfoId, dataPos.dataInfoId);
    }

    @Override
    public int hashCode() {
        if (hash == 0) {
            hash = Objects.hash(dataInfoId, registerId);
        }
        return hash;
    }

}
